package org.example.spring_blog.tests;

import org.example.spring_blog.common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;

import java.io.IOException;

public class LoginPage extends Utils {
    public static String url = "http://127.0.0.1:8080/blog_login.html";

    public LoginPage() {
        super(url);
    }

    /**
     * 检查页面是否加载成功
     */
    public void loginPageRight() {
        driver.findElement(By.cssSelector("#username"));
        driver.findElement(By.cssSelector("#password"));
    }

    /**
     * 成功登录
     */
    public void loginSuc() throws InterruptedException {
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();


        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#submit")).click();

        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)"));

        driver.navigate().back();
    }

    /**
     * 失败登录
     */
    public void loginFail() throws IOException, InterruptedException {
        driver.navigate().refresh();

        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("1234567");
        driver.findElement(By.cssSelector("#submit")).click();


    }
}
